package advertising.handler

import advertising.AppParams
import org.apache.commons.lang3.StringUtils
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hbase.HBaseConfiguration
import org.apache.hadoop.hbase.client.ConnectionFactory

//  .--,       .--,
// ( (  \.---./  ) )
//  '.__/o   o\__.'
//     {=  ^  =}
//      >  -  <
//     /       \
//    //       \\
//   //|   .   |\\
//   "'\       /'"_.-~^`'-.
//      \  _  /--'         `
//    ___)( )(___
//   (((__) (__)))    高山仰止, 景行行止; 虽不能至, 心向往之.
//                    High mountains, scenery. Although not to, the heart yearns for it. 
object HBaseHandler {

  private def getClusterInfo() = {
    val nodes = StringUtils.split(AppParams.hbaseZookeeperQuorumCluster, " ")
    val port = AppParams.hbaseZookeeperQuorumPort
    val sb = new StringBuilder()
    for(node <- nodes) {
      sb.append(node)
      sb.append(':')
      sb.append(port)
      sb.append(',')
    }
    sb.substring(0, sb.length - 1).toString()
  }
  private val conf: Configuration = HBaseConfiguration.create()

  {
    val clusterInfo = getClusterInfo()
    conf.set("hbase.zookeeper.quorum", clusterInfo)
  }

  def getConnection = {
    ConnectionFactory.createConnection(conf)
  }

}
